package com.hsy.swu.home.course

import com.hsy.swu.hsyutils.MLog
import java.time.LocalDate
import java.time.temporal.ChronoUnit

object CourseUtils {
    /** 生成周数的日期表，传入的 date是开学第一天 */
    fun generateWeeksList(
        date: LocalDate,
        semesterTotalWeeks: Int = 20
    ): List<Triple<Int, Int, Int>> {
        val dateList = mutableListOf<Triple<Int, Int, Int>>()
        repeat(semesterTotalWeeks) { week ->  // 生成学期总上课周数的日期，默认 20周
            repeat(7) { day ->  // 循环 7 次，生成一周的日期
                val newDate = date.plusWeeks(week.toLong()).plusDays(day.toLong())
                dateList.add(Triple(newDate.year, newDate.monthValue, newDate.dayOfMonth))
            }
        }
        return dateList
    }

    /** 获取间隔天数 */
    fun getIntervalDays(startDate: LocalDate): Int {
        val today = LocalDate.now()
        var intervalDays = ChronoUnit.DAYS.between(startDate, today).toInt()
        intervalDays = if (intervalDays >= 0) intervalDays else 0
        MLog.attention("天数 -> $intervalDays")
        return intervalDays
    }
}